﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.Common.Logging;
using ETL.DataAccess;
using ETL.Entity;

namespace ETL.Business.Handlers.ProjectTaskHandler
{
    public class GetLastestProjectTask
    {
        private readonly ProjectTaskRepository _projectTaskRepository;

        public GetLastestProjectTask(ProjectTaskRepository projectTaskRepository)
        {
            _projectTaskRepository = projectTaskRepository;
        }
        public GetLastestProjectTask()
        {
            _projectTaskRepository = new ProjectTaskRepository();
        }
        public virtual ProjectTaskModel Execute(string userid)
        {
            ProjectTaskModel projectTasksModel = null;
            try
            {
                // try to get from db
                TASK projectTasksData = _projectTaskRepository.GetLastProjectTask(userid);

                // parse to business model
                if (projectTasksData != null)
                {
                    projectTasksModel = new ProjectTaskModel(projectTasksData);
                }
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }

            return projectTasksModel;

        }
    }
}
